package cn.bugDance.trigger.listener;

import cn.bugDance.domain.activity.event.ActivitySkuStockOverEvent;
import cn.bugDance.domain.activity.service.quota.IRaffleActivityQuotaService;
import cn.bugDance.types.response.BaseEvent;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.TypeReference;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
@Slf4j
@RocketMQMessageListener(topic = "skuStockOverTopic", consumerGroup = "sku-stock-consumer-group")
public class ActivitySkuStockOverListener implements RocketMQListener<String> {

    @Resource
    private IRaffleActivityQuotaService raffleActivityQuotaService;


    @Override
    public void onMessage(String mqMessage) {
        try{
            BaseEvent<Long> message = JSON.parseObject(mqMessage, new TypeReference<BaseEvent<Long>>(){});
            if(message == null) return;
            Long sku = message.getData();
            //raffleActivityQuotaService.clearActivitySkuJobQueue(sku);
            //raffleActivityQuotaService.updateActivitySkuStockOver(sku);
            log.info("【活动监听层-ActivitySkuStockOverListener】: 活动sku: {} 库存为0， 数据库直接扣减", sku);
        }catch(Exception e){
            log.info("【活动监听层-ActivitySkuStockOverListener】: 活动sku置0异常");
        }

    }
}
